<?php 
/**
*	【文档】应用的接口
*	createname：雨中磐石
*	homeurl：http://www.rockoa.com/
*	Copyright (c) 2016 rainrock (www.rockoa.com)
*	Date:2016-08-08
*/
class wordClassAction extends apiAction
{
	
	
	
	//获取数据
	public function getdataAction()
	{
		$barr = m('word')->getdata();
		$this->showreturn($barr);
	}
	
	
	//保存文件
	public function savefileAction()
	{
		m('word')->savefile();
		$frs = m('file')->getone($this->post('sid'));
		$this->showreturn($frs);
	}
	
	//创建文件夹
	public function createfolderAction()
	{
		
		$cqid 	= $this->post('cqid');
		$typeid = (int)$this->post('typeid','0');
		$name 	= $this->post('name');
		
		$arr 	= m('word')->createfolder($name, $cqid, $typeid);
		$this->showreturn($arr);
	}
	
	//从命名
	public function renameAction()
	{
		$id 	= (int)$this->post('id');
		$name 	= $this->getvals('name');
		$type 	= $this->post('type');
		m('word')->update("`name`='$name'", $id);
		$this->showreturn('');
	}
  
      //获取分区

    public function getfqAction()
    {
        $cid = (int)$this->post('cid', '');
        if(!$cid){
            return returnerror('分区参数错误');
        }
		$frs = m('worc')->getone($cid);
		$this->showreturn($frs);
    }

	    /**
     *    更新保存文件
     */
    public function saveupdatefileAction()
    {

        $newid = (int)$this->rock->post('newid', 0);//新文件id
        $cid = (int)$this->rock->post('cqid', 0);//分区id
        $sid = (int)$this->rock->post('sid', 0);//原来的文件id
        $typeid = (int)$this->rock->post('typeid', '0');//文件路径id
        $file = m('file');
        $data = $file->getone($newid);
		$olddata = $file->getone($sid);
        if ($olddata && $data) {
            //替换原来的id内容
            $result = $file->update(array(
                'fileext' => $data['fileext'],
                'filename' => $data['filename'],
                'filepath' => $data['filepath'],
                'filesize' => $data['filesize'],
                'filesizecn' => $data['filesizecn'],
                'filetype' => $data['filetype'],
                'thumbpath' => $data['thumbpath'],
                'old_filepath' => $olddata['filepath']
            ), '`id`=' . $sid . '');//更新

            //更新时间
            $word = m('word');
            $time = $this->rock->now;
            $word->update("`optdt`=$time", '`fileid`=' . $sid . '');
            if ($result) {
                //删除新的文件
                $rst = $file->delete($newid);
                if ($rst) {
                    return returnsuccess();
                }
            }

            return returnerror('更新失败');

        }

        return returnerror('文件更新出现异常');

    }



	//删除
	public function delfileAction()
	{
		$id 	= (int)$this->post('id');
		$barr 	= m('word')->delword($id);
		if(!$barr['success']){
			$this->showreturn('',$barr['msg'],201);
		}else{
			$this->showreturn('');
		}
	}
	
	//共享
	public function shatefileAction()
	{
		m('word')->sharefile();
		$this->showreturn('');
	}
	
	public function movegetAction()
	{
		return m('word')->getworcfolder();
	}
	
	public function movefileAction()
	{
		$barr = m('word')->movefile();
		if(!$barr['success']){
			$this->showreturn('',$barr['msg'],201);
		}else{
			$this->showreturn('');
		}
	}

	
}